Skip to content

feat: add dynamicColor prop and DynamicTheme refactor#4925

Open
adrcotfas wants to merge 1 commit into@adrcotfas/refactor/accesibilityfrom
@adrcotfas/refactor/dynamic_themes
Open

feat: add dynamicColor prop and DynamicTheme refactor#4925
adrcotfas wants to merge 1 commit into@adrcotfas/refactor/accesibilityfrom
@adrcotfas/refactor/dynamic_themes

Conversation

@adrcotfas
Copy link
Copy Markdown
Collaborator

Motivation

Before this PR, using dynamic colors required every consumer to wire up the same boilerplate: import DynamicLightTheme/DynamicDarkTheme, detect Android API 31+ themselves, write a useMemo to switch between them, and keep it in sync with dark mode. The library provided the building blocks but left the assembly to the app.

This PR absorbs that complexity into PaperProvider via a single dynamicColor prop. Pass dynamicColor and the provider handles palette selection, API level detection, dark/light switching, and graceful fallback on iOS/web -- with no app-side logic needed.

Alongside that, the DynamicTheme.android.tsx implementation is refactored from ~500 lines of repetitive pick() calls into a typed role-map table with Palette.* ref constants as ground truth. This fixes two latent bugs in the original: error roles and MCL-only surface roles were calling PlatformColor with hex strings on API 31-33 (invalid, silently transparent), and surfaceVariant was missing its API 31 accent resources entirely.

Other changes in scope: ThemeBase inlined into Theme (kept as a deprecated Pick<> alias), and isDynamicColorSupported exported from the library root so consumers can conditionally show a dynamic theme toggle without re-implementing the platform check.

Related issue

Related issue
See https://www.notion.so/callstack/React-Native-Paper-Foundation-for-MD3-Expressive-34c5d027c0f880edba3df107cd35946f?source=copy_link

Merge order:

Test plan

  • yarn typescript -- no new type errors
  • yarn test -- all tests pass

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

The mobile version of example app from this branch is ready! You can see it here.

@adrcotfas adrcotfas force-pushed the @adrcotfas/refactor/dynamic_themes branch from 62ea8dc to 96603d4 Compare May 7, 2026 14:11
@callstack-bot
Copy link
Copy Markdown

Hey @adrcotfas, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants